Make Kernel Image:
git clone https://github.com/torvalds/linux
cd linux
make menuconfig
make - j8
>> > ls ./arch/x86_64/boot - al
lrwxrwxrwx - generalzero 3 Apr 20:07 bzImage -> ../../x86/boot/bzImage
Create initramfs:
yay - S uboot-tools
git clone git://git.busybox.net/busybox
cd busybox
make config
make - j8
make install
cd ..
mkdir - p initramfs/bin initramfs/sbin initramfs/etc initramfs/proc initramfs/dev initramfs/usr/bin initramfs/usr/sbin
cp - a busybox/_install/* ./initramfs
cd initramfs
cat > ./init << EOF
mount -t proc none /proc
mount -t sysfs none /sys
exec /bin/sh
EOF
chmod +x ./init
find . - print0 | cpio -- null - ov -- format= newc | gzip - 9 > ../initramfs.cpio.gz
cd ..
mkimage - A x86_64 - O linux - T ramdisk - C gzip - d initramfs.cpio.gz initramfs.cpio.gz.uboot
There is a issue with busybox with the net kernel so lets use an older docker to compile it.
Building busybox with Docker:
sudo docker pull debian:bullseye
sudo docker run - it - v ` pwd ` :/busybox -- name busybox-builder debian:bullseye
apt update
apt install - y build-essential wget git
cd /busybox
make - j$ ( nproc )
make install CONFIG_PREFIX=/busybox/_install
Setup TFTP:
mkdir - p ./tftp/recovery
cp ./linux/arch/x86_64/boot/* Image* ./tftp/recovery
cp ./initramfs.cpio.gz* ./tftp/recovery
cd ./tftp/recovery
cat > ./compose.yml << EOF
services:
tftp-server:
image: taskinen/tftp:latest
entrypoint: in.tftpd
command: -L -4 --secure --address 0.0.0.0:69 --verbosity 3 /var/tftpboot
ports:
- "0.0.0.0:69:69/udp"
volumes:
- ./recovery:/var/tftpboot:ro
restart: unless-stopped
EOF
sudo docker-compose down && sudo docker-compose pull && sudo docker-compose up -- remove-orphans - d
Create Bootable image:
yay - S qemu-tools qemu-img
qemu-img create sdcard.img 4G
sudo parted -- script sdcard.img \
mktable gpt
mkpart primary ext4 1M 500M
mkpart primary ext4 500M 100%
set 1 boot on
sudo losetup -- show - f sdcard.img
sudo mkfs.ext4 /dev/mapper/loop0p1
sudo mkfs.ext4 /dev/mapper/loop0p2
sudo mount /dev/mapper/loop0p2 /mnt/sdcard
sudo debootstrap -- arch= x86_64 -- foreign bookwork /mnt/sdcard
sudo chroot /mnt/sdcard bash
/debootstrap/debootstrap -- second-stage
exit
apt install-y sudo ifupdown net-tools ntpupdate openssh-server udev
passwd
exit
sudo INSTALL_PATH=/mnt/sdcard/boot make install
sudo INSTALL_MOD_PATH=/mnt/sdcard make modules_install
Cleanup Image:
sudo umount /dev/mapper/loop0p1
sudo umount /dev/mapper/loop0p2
sudo kxpart - d /dev/loop0
sudo losetup - d /dev/loop0